package com.kuang.springcloud.controller;

import com.kuang.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class ConsumerController {

//    private static final String ADDRESS = "http://localhost:8001";

    //因为多个集群共用一个服务名，所以根据服务名称去获取指定的url，所以这里应该是变量
    private static final String ADDRESS = "http://SPRINGCLOUD-PROVIDER-DEPT";

    @Autowired
    RestTemplate restTemplate;

    /**
     * 调不通
     */
    @RequestMapping("/consumer/add")
    public boolean queryDeptById(Dept dept){
        return restTemplate.postForObject(ADDRESS +"/dept/add",dept,Boolean.class);
    }

    @RequestMapping("/consumer/get/{id}")
    public Dept queryDeptById(@PathVariable("id") Long id){
        return restTemplate.getForObject(ADDRESS +"/dept/get/{id}",Dept.class,id);
    }

    @RequestMapping("/consumer/list")
    public List<Dept> queryDeptAll() {
        return restTemplate.getForObject(ADDRESS + "/dept/list", List.class);
    }

}
